import subprocess

def add(a, b):
    """加法方法"""
    return a + b

def division(a, b):
    """除法方法"""
    if b == 0:
        raise ValueError("Division by zero")
    return a / b

def system(command):
    """执行系统命令"""
    try:
        result = subprocess.run(
            command, 
            shell=True, 
            capture_output=True, 
            text=True,
            check=True
        )
        return {
            'stdout': result.stdout,
            'stderr': result.stderr,
            'returncode': result.returncode
        }
    except subprocess.CalledProcessError as e:
        return {
            'stdout': e.stdout,
            'stderr': e.stderr,
            'returncode': e.returncode,
            'error': str(e)
        }
    except Exception as e:
        return {
            'error': f"Execution failed: {str(e)}"
        }

# 可用方法列表
METHODS = {
    'add': add,
    'division': division,
    'system': system
}    
